package com.nikkerball.apps.darkhorse.model.core;

import com.nikkerball.apps.darkhorse.model.base.NameObject;
import com.nikkerball.apps.darkhorse.model.evaluation.topic.TopicEvaluation;
import org.hibernate.annotations.Cascade;

import javax.persistence.*;
import java.util.List;

import static org.hibernate.annotations.CascadeType.*;

/**
 * Represents a general Topic
 */
@Entity
@Table(name = "Topic")
public class Topic extends NameObject {

    // ----- instance fields -----

    private List<ClassYear> classYears;

    private List<TopicEvaluation> topicEvaluations;

    // ----- constructors -----

    public Topic() {
        super();
    }

    public Topic(String name) {
        super(name);
    }

    // ----- public methods -----

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(name = "ClassYear_Topic", joinColumns = @JoinColumn(name = "GeneralId"),
            inverseJoinColumns = @JoinColumn(name = "ClassYearId"))
    public List<ClassYear> getClassYears() {
        return this.classYears;
    }

    public void setClassYears(List<ClassYear> classYears) {
        this.classYears = classYears;
    }

    @OneToMany(mappedBy = "topic")
    @Cascade({MERGE, PERSIST, SAVE_UPDATE, DETACH, DELETE})
    public List<TopicEvaluation> getTopicEvaluations() {
        return this.topicEvaluations;
    }

    public void setTopicEvaluations(List<TopicEvaluation> topicEvaluations) {
        this.topicEvaluations = topicEvaluations;
    }
}
